﻿using System;

namespace InterfaceTest
{
    //游泳接口
    interface ISwimable
    {
        void Swimming();
    }

    //游泳实现类
    class SwimWithflippers : ISwimable
    {
        public void Swimming()
        {
            Console.WriteLine("我能用脚蹼游泳！！");
        }
    }
    class SwimNoWay : ISwimable
    {
        public void Swimming()
        {
            Console.WriteLine("我不能用游泳！！");
        }
    }
    //鸭子飞 接口
    interface IFlyable
    {
        void Flying();
    }
    class Flystyle : IFlyable
    {
        public void Flying()
        {
            Console.WriteLine("我不能用翅膀飞翔！！");
        }
    }
    class FlyNoWay : IFlyable
    {
        public void Flying()
        {
            Console.WriteLine("我能用翅膀飞翔！！");
        }
    }
    //鸭子叫 接口
    interface IShoutable
    {
        void Shouting();
    }
    //鸭子叫 实现
    class ShoutGaga : IShoutable
    {
        public void Shouting()
        {
            Console.WriteLine("嘎嘎叫！");
        }
    }
    class ShoutScream : IShoutable
    {
        public void Shouting()
        {
            Console.WriteLine("尖叫！");
        }
    }
    class ShoutNoWay : IShoutable
    {
        public void Shouting()
        {
            Console.WriteLine("不能叫！");
        }
    }

    //鸭子的超类
    abstract class Duck
    {
        public ISwimable Swimbehavior;
        public IShoutable ShoutBehavior;
        public IFlyable FlyBehavior;
        public void performSwim()
        {
            Swimbehavior.Swimming();
        }
        public void performShout()
        {
            ShoutBehavior.Shouting();
        }
        public void performFiy()
        {
            FlyBehavior.Flying();
        }
    }
    //真实的鸭子
    class RealDuck : Duck
    {
        public RealDuck()
        {
            Swimbehavior = new SwimWithflippers();
            ShoutBehavior = new ShoutGaga();
            FlyBehavior = new Flystyle();
        }

    }

    //橡皮鸭子
    class RubberDuck : Duck
    {
        public RubberDuck()
        {
            Swimbehavior = new SwimNoWay();
            ShoutBehavior = new ShoutScream();
            FlyBehavior = new FlyNoWay();
        }

    }

    //木头鸭子
    class WoodDuck : Duck
    {
        public WoodDuck()
        {
            Swimbehavior = new SwimNoWay();
            ShoutBehavior = new ShoutNoWay();
            FlyBehavior = new FlyNoWay();
        }

    }
    class NanJingDuck : Duck
    {
        public NanJingDuck()
        {
            Swimbehavior = new SwimNoWay();
            ShoutBehavior = new ShoutNoWay();
            FlyBehavior = new FlyNoWay();
        }

    }


    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("请选择您要查看的鸭子，如下：");
                Console.WriteLine("1、真实鸭子 2、橡皮鸭子 3、木头鸭子 4、南京板鸭 0、退出");
                string name = Console.ReadLine();
                if (name == "0") break;
                Duck x = null;
                if (name == "1")
                {
                    x = new RealDuck();
                }
                if (name == "2")
                {
                    x = new RubberDuck();
                }
                if (name == "3")
                {
                    x = new WoodDuck();
                }
                if (name == "4")
                {
                    x = new NanJingDuck();
                }
                if (x != null)
                {
                    x.performSwim();
                    x.performShout();
                }
                else
                {
                    Console.WriteLine("系统找不到您选择的鸭子……");
                }
            }
        }
    }
}